home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DEBUG / WATCHES / WATCHES.TXT < prev    next >
Text File  |  1996-06-21  |  24KB  |  748 lines

  1. (*
  2.  
  3.  
  4.      See/text-search in file COMM.TXT for "WATCHES.TXT".
  5.  
  6.  
  7.      WATCHES  TXT   :watches & how to format them; values & how they
  8.                      are stored in memory; TP-IDE; (guess from 6.0 onwards)
  9.  
  10.   ................................................................
  11.   "Beginners only"  {to skip, text-search "WATCH-FORMATS"
  12.      Watches invisible ?
  13.        UNITs
  14.      Watches invisible after CTRL-F9 and a run-error
  15.      Watches = Variables only?
  16.   ................................................................
  17.   WATCH-FORMATS
  18.   VALUE & HOW IT IS STORED
  19.    POINTERS
  20.   MANY VARS TO DISPLAY
  21.   BINARY FORMAT
  22.  
  23.   ================================================================
  24.  
  25.  
  26.   ................................................................
  27.  
  28.  
  29.   "Beginners only"  {to skip, text-search "WATCH-FORMATS"
  30.  
  31.      Watches are what you get via eg. CTRL+F7. You put variables
  32.      in the watches-window. It watches what the variables are
  33.      looking at. To watch them carefully, their value is closely
  34.      monitored. If you want to keep a close eye on this, you can
  35.      split your monitor with ALT-W, T, and have a look at the
  36.      watches in the lower window.
  37.  
  38.  
  39.      (BTW, you can change a value with ALT+D, E while the program is
  40.       "running", i.e. while debugging.
  41.      )
  42.  
  43.  
  44.      Watches invisible ?
  45.        Well, firstly you need to enable the compiler to compile
  46.        with the necessary information for debugging, before you
  47.        running a program step by step - and watching any variables.
  48.        See the online-help on eg.: $D $L
  49.        (put cursor on $D, press CTRL-F1}
  50.        ((also, there are some notes in file: Define.txt of upload
  51.          loader.zip
  52.        ))
  53.  
  54.        UNITs
  55.          Note that if a program uses units you can step through
  56.          their routines, only if the units are compiled with
  57.          the corresponding $... specifications.
  58.  
  59.          Also: If you press F8 and the highlighted line jumps to
  60.          the "BEGIN" of the main program, you can then step through
  61.          the init-code (BEGIN...END part of units) of all such
  62.          compiled units by pressing F7.
  63.  
  64.          You can however, simply put an END instead of a BEGIN END
  65.          in the interface of an unit which would "avoid" this. If
  66.          there is no "real" ini-code, well, you can still put BEGIN END
  67.          in a unit, which then perhaps serves to check which units are
  68.          loaded when (stepping via F7), etcetera.
  69.  
  70.          Units as CRT, SYSTEM, etc. are not compiled for this kind of
  71.          "stepping" via F7.
  72.  
  73.  
  74.        Hence, you'd need to press F7 or F8 to start debugging
  75.        before watches "become visible". Also, you'd need to take
  76.        care that watches inside procedures might have the same
  77.        name as global variables. Inside a procedure P, the
  78.        watch-variable "w" represents the "w" of the procedure,
  79.        outside the procedure it refers to the global variable "w".
  80.  
  81.  
  82.        You can specify a variable however:
  83.  
  84.        Program x;
  85.        var w:word;
  86.          procedure a;
  87.          var w:word;
  88.          begin
  89.          end;
  90.        begin
  91.          a;
  92.        end.
  93.  
  94.        Here you can use: "x.w" for the global variable "w", and
  95.        "a.w" for the procedure's variable "w"
  96.  
  97.        The watch "w" may refer to any of these, depending on
  98.        whether "the program" is *currently* "inside the procedure"
  99.        or not.
  100.  
  101.        ((
  102.          Other specifications can apply to the units CRT, DOS, etc.
  103.          eg.: "crt.lastmode". You can of course also use this to
  104.          "de-reference" procedure/functions. "built-in" routines
  105.          are de-referenced with System.*
  106.          eg.:
  107.            program x; uses crt;
  108.            {---------------------------------------------------------------}
  109.            PROCEDURE writeln (s:string);
  110.            BEGIN
  111.              system.writeln(#7,s); {#7=bell character (ASCII), beeps}
  112.            END;
  113.            {---------------------------------------------------------------}
  114.            BEGIN
  115.              ClrScr;
  116.              writeln('...NET !');
  117.              System.Writeln('...first service.');
  118.              System.Writeln('...quiet, please...');
  119.              writeln('...OUT !');
  120.            END.
  121.        ))
  122.  
  123.  
  124.      Watches invisible after CTRL-F9 and a run-error
  125.        When your program stops with a run-error the watches of a
  126.        procedure might no longer be "visible". For test-purposes
  127.        you might instead use a global variable, which will still
  128.        be visible:
  129.        (eg included via $define... compiling)
  130.        ((about $define, see file DEFINE.TXT / upload: Loader.zip))
  131.  
  132.        For example:
  133.  
  134.        Program x;
  135.        var w:word;
  136.          procedure a;
  137.          var b:byte;
  138.          begin
  139.            b:=4;
  140.            w:=4;
  141.            runError;
  142.            {<function to artificially cause a runError as if a "real"
  143.             error had occurred.
  144.            }
  145.          end;
  146.        begin
  147.          a;
  148.        end.
  149.  
  150.        Follwing a screen-copy *after* this sample code has been run:
  151.  
  152.  
  153.    File  Edit  Search  Run  Compile  Debug  Tools  Options  Window  Help
  154.  ╔═[■]════════════════════════════ WATCHES.TXT ═══════════════════════════1═[·]═╗
  155.  ║ Error 0: Runtime error.                                                      ·
  156.  ║         procedure a;                                                         ▒
  157.  ║         var b:byte;                                                          ▒
  158.  ║         begin                                                                ■
  159.  ║           b:=4;                                                              ▒
  160.  ║           w:=4;                                                              ▒
  161.  ║           runError;                                                          ▒
  162.  ║           {function to artificially cause a runError as if a "real"          ▒
  163.  ║            error had occurred.                                                ▒
  164.  ║           }                                                                  ▒
  165.  ║         end;                                                                 ▒
  166.  ║       begin                                                                  ▒
  167.  ║         a;                                                                   ▒
  168.  ║       end.                                                                   ·
  169.  ╚═·════ 73:1 ═════·■▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒·─┘
  170.  ┌────────────────────────────────── Watches ─────────────────────────────2─────┐
  171.  │ b: Unknown identifier                                                        │
  172.  │ w: 4                                                                         │
  173.  │                                                                              │
  174.  │                                                                              │
  175.  │                                                                              │
  176.  └──────────────────────────────────────────────────────────────────────────────┘
  177.   F1 Help  F2 Save  F3 Open  Alt+F9 Compile  F9 Make  Alt+F10 Local menu
  178.  
  179.        Note:  Variable w is still "visible", when variable b is not.
  180.  
  181.  
  182.  
  183.  
  184.      Watches = Variables only?
  185.        Not necessarily. You can easily enter any "expression"
  186.        If it is wrong, the IDE will tell you - that's about all.
  187.        Invalid format-specifiers are mostly be simply ignored.
  188.  
  189.        Not forgetting that if you don't have a pocket calculator
  190.        handy, you can also do calculations with the IDE. Later on,
  191.        I'll show how this "calculator" could also convert decimal
  192.        values to hexa-decimal.
  193.  
  194.  
  195.        Program x;
  196.        var w:word;
  197.        begin
  198.          w:=4;
  199.        end.
  200.  
  201.        ╔═[■]══════════════════════════════ Watches ══════
  202.        ║ w: 4
  203.        ║ w * 30 - 50: 70
  204.        ║ 1.25 * 4 + (1.2 / 3 ): 5.4
  205.        ║ Oh no, it's an: Unknown identifier
  206.        ║ trunc(2.4) * trunc(2.5): 4
  207.        ║ w mod 2: 0
  208.        ║ w > 2.5: True
  209.        ║ not true: False
  210.  
  211.        ...etc...type-casts...etc...
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.   ................................................................
  220.  
  221.  
  222.  
  223.  
  224.   WATCH-FORMATS
  225.  
  226.      You can specify a couple of formats with which the value of a
  227.      "watch-variable" is to be displayed. And, if you want ice for
  228.      dessert, you can even combine them. That is, both combinations
  229.      of values and/or variables.
  230.  
  231.      I assume this to be easier to explain by giving so called
  232.      screen-dumps as examples. You can also use this file in the
  233.      IDE and check the code yourself. If you want to run some
  234.      sample code, simply move the end-of-comment sign (the
  235.      comment sign with an asterix* ) above the sample code's
  236.      "program" start-line.
  237.  
  238.  
  239.      By default strings and arrays might appear quite "ugly":
  240.  
  241.  
  242.      program x; var s:string; a:array[1..100] of char; b:byte;
  243.      begin
  244.        s[0]:=#100; for b:=32 to 132 do s[b-31]:=char(b);
  245.        for b:=100 to 200 do a[b-99]:=char(b);
  246.      end.
  247. ┌────────────────────────────────── Watches ─────────────────────────────1─────┐
  248. │ s: ' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefg│
  249. │ a: ('d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','│
  250. │                                                                              │
  251.  
  252.      Both variables do not fit on the screen, and you'd need to use
  253.      CURSOR-RIGHT etc. to see "higher values".
  254.  
  255.      You could try this format specifier for variables:
  256.        s[40],40
  257.      => beginning with element #40, display 40 "elements".
  258.  
  259. ╔═[■]══════════════════════════════ Watches ═════════════════════════════1═[·]═╗
  260. ║ s: ' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefg·
  261. ║ s[40],40: 'G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W'■
  262. ║ a: ('d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','▒
  263.  
  264.  
  265.  
  266.  
  267.      Sometimes, you might prefer to see values in hexa-decimal format.
  268.      You can add ",h" - but this won't work with strings/chars. Yet,
  269.      alternatively you can specify ",m" which displays "WHAT IS ACTUALLY
  270.      STORED IN MEMORY", which displays in hexa-decimal format.
  271.  
  272. ┌────────────────────────────────── Watches ─────────────────────────────1─────┐
  273. │ s: ' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefg│
  274. │ s[40],40: 'G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W'│
  275. │ s[40],40m: 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59 5A 5B 5C │
  276.  
  277.  
  278.  
  279.  
  280.      "s[40],40" has "s" displayed like the array-of-char "a" was displayed.
  281.      This can be considered ugly, since one char uses 4 "digits" to get
  282.      displayed, eg: 'G',
  283.  
  284.      For vanilla ice-cream, you could alternatively combine the format-
  285.      specifiers ",c" (char) with ",m":
  286.  
  287. ╔═[■]══════════════════════════════ Watches ═════════════════════════════1═[·]═╗
  288. ║ s: ' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefg·
  289. ║ s[40],40: 'G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W'▒
  290. ║ s[40],40mc: 'GHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmn'                       ■
  291. ║ a: ('d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','▒
  292. ║ a,mc: 'defghijklmnopqrstuvwxyz{|}~ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐·
  293.  
  294.  
  295.      The "mc" specifier is s.th to keep in mind whenever you want
  296.      to format as "ASCII-code chars".
  297.  
  298.      File WATCHES2.txt gives an example for ASM-registers as
  299.      "watches as chars" - and for other points discussed further on
  300.      here in this file.
  301.  
  302.      ((
  303.        BTW, the ",c" is meant to display the #0..#31 as "ASCII-chars"
  304.        (opposed to displaying them as #0, #1, etc.) Yet, this is not
  305.        a good example to include, since it may cause havoc when printing.
  306.        An example for this & "strings"-const is in file Watches3.txt
  307.      ))
  308.  
  309.  
  310.  
  311.      Now, if you want to see decimal/Hexa-decimal equivalents,
  312.      these are some ideas:
  313. ┌────────────────────────────────── Watches ─────────────────────
  314. │ s[40],40: 'G','H','I','J','K','L','M','N','O','P','Q','R','S','
  315. │ s[40],40m: 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 5
  316. │ s[40],40md: 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
  317. │ 'G': 'G'
  318. │ byte('G'): 71
  319. │ byte('G'),h: $47
  320.  
  321.  
  322.  
  323.  
  324.   VALUE & HOW IT IS STORED
  325.  
  326.      ",m" might help to visualize how "multi-byte unities" are actually
  327.      stored in memory:
  328.  
  329.      program x;
  330.      var pB:^Byte; w:word;
  331.      begin
  332.        w:=259;
  333.        pB:=@w;
  334.      end.
  335.      ┌────────────────────────────────── Watches ───────────────────────
  336.      │ pB^,h: $3
  337.      │ pB^,2m: 03 01
  338.      │ w: 259
  339.      │ w,h: $103
  340.      │ w,m: 03 01
  341.  
  342.  
  343.      ",m" by default displays memory starting from the start-address
  344.      of the variable "over the length/size" of the variable.
  345.  
  346.      As you can see the 2-bytes variable "w" has the hexa-VALUE $0103.
  347.      Yet, it is STORED as $0301 - as "w,m" indicates.
  348.  
  349.      Also, see below about $A+ and $A-  (Text-search: "!!!")
  350.  
  351.      As pB is a pointer on a single byte only, pB^ does represent just
  352.      one byte of w instead of its two bytes. Therefore the format
  353.      specifier ",2" to display the two bytes stored in memory, "pB^,2m"
  354.  
  355.      Since the value of pB^ is $03, it obviously points to what "w,m"
  356.      displays as the "high-byte" ("left-most" byte). More about this
  357.      will follow later on, when giving a suggestion for "Binary format"
  358.      and all that jazz.
  359.  
  360.  
  361.  
  362.  
  363.  
  364.    POINTERS
  365.  
  366.      ( This links to file COMM.TXT (text-search for "WATCHES.TXT")
  367.        (about pointers<->strings as parameters for child-processes)
  368.        upload: loader.zip
  369.      )
  370.  
  371.      PROGRAM x;
  372.      {$D+,L+,I+,R+,S+,Q+,V+,Y+}
  373.      VAR s:string; pByte:^byte;
  374.      BEGIN
  375.        pByte:= PTR( $3344, $5566 ); {artificial value for testing only}
  376.  
  377.        s[0]:=#4; {<set length to 4}
  378.  
  379.        {>move the "address-pByte-is-pointing-to" to the string}
  380.        move( pByte , s[1], 4);  { pByte = @pByte^ }
  381.      END.
  382.      {-----------------------------------------------------------------}
  383. ╔═[■]══════════════════════════════ Watches ══════════════════════
  384. ║ pByte: Ptr($3344,$5566)
  385. ║ pByte,m: 66 55 44 33
  386. ║ @pByte^: Ptr($3344,$5566)
  387. ║ @pByte^,p: 3344:5566
  388. ║ s: 'fUD3'
  389. ║ s,m: 04 66 55 44 33 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  390. ║ s[1],4m: 66 55 44 33
  391.  
  392.      As you can see, while a pointer is considered to be Ptr($3344,$5566)
  393.      that is Ptr($segment,$offset), it is differently stored in memory.
  394.      Here as: pByte,m: 66 55 44 33,
  395.  
  396.      Which is reflected in the type PtrRec used in unit WinDos to
  397.      "access" a pointer:
  398.        TYPE
  399.          PtrRec = RECORD
  400.                     ofs, seg:word;
  401.                   END;
  402.  
  403.      Now, to obtain the word-value of eg. the segment you might eg. use
  404.      the function seg():
  405.        "w:=seg(pointerVar)"
  406.      or type-casting:
  407.        "w:= PtrRec( pointerVar ).seg"  (etc.... word()<-> offset, etc.)
  408.  
  409.      In a Bpascal forum message, Peter Below (CIS address 100113,1101)
  410.      strongly recommended to me using type-casting, saying that, the
  411.      Seg/Ofs functions would actually load the value into CPU-registers,
  412.      and that with invalid values this would cause a GPF.
  413.  
  414.  
  415.  
  416.  
  417.  
  418.   MANY VARS TO DISPLAY
  419.      If you have many byte/words as watches, each will "take up" one line.
  420.      Even if they might not need more than a couple of columns to display
  421.      a value.
  422.  
  423.      To not waste all those lines, you might eg. declare them following
  424.      one another in the var-statement, eg:  var a,b,c,d:byte;
  425.  
  426.      program x;
  427.      var a,b:byte; c:byte; d:byte;
  428.          s:string;
  429.          e:byte;
  430.      begin
  431.        a:=1;b:=2;c:=3;d:=4;e:=5;
  432.        move(a,s[1],5);
  433.      end.
  434. ┌────────────────────────────────── Watches ─────────────────────────────
  435. │ a: 1
  436. │ b: 2
  437. │ c: 3
  438. │ d: 4
  439. │ e: 5
  440. │ a,5: 1,2,3,4,0
  441. │ s,m: 00 01 02 03 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  442.  
  443.      Note
  444.       -"a,5" does not display "e", as variable "s" was declared before "e".
  445.       -(BTW, the 0 in a,5 is obviously the length byte of s)
  446.  
  447.  
  448.      (((
  449.      ....BTW...BEGIN...................
  450.          While using
  451.            var a,b:byte; c:byte;
  452.          or
  453.            var a,b,c:byte;"
  454.          did not seem to make any difference, I found a difference when
  455.          using "var" several times:
  456.  
  457.          program x;
  458.          var a,b:byte;
  459.          var c:byte;
  460.          var d:byte;
  461.          var s:string;
  462.              e:byte;
  463.          begin
  464.            a:=1;b:=2;c:=3;d:=4;e:=5;
  465.            move(a,s[1],5);
  466.          end.
  467.  
  468.          ┌────────────────────────────────── Watches ───────────
  469.          │ a: 1
  470.          │ b: 2
  471.          │ c: 3
  472.          │ d: 4
  473.          │ e: 5
  474.          │ a,5: 1,2,3,0,4
  475.          │ s,m: 00 01 02 03 00 04 00 00 00 00 00 00 00 00 00 00
  476.  
  477.  
  478.          And mixing bytes/words:
  479.  
  480.          program x;
  481.          {$A+,B-,D+,E+,F-,G-,I+,L+,N-,O-,P-,Q-,R-,S+,T-,V+,X+}
  482.          var a,b,c:byte; d:word; e:byte;
  483.          var s:string;
  484.          begin
  485.            a:=1;b:=2;c:=3;d:=259;e:=5;
  486.            move(a,s[1],7);
  487.          end.
  488.          ┌────────────────────────────────── Watches ─────
  489.          │ a: 1
  490.          │ b: 2
  491.          │ c: 3
  492.          │ e: 5
  493.          │ a,7: 1,2,3,0,3,1,5
  494.          │ a,7m: 01 02 03 00 03 01 05
  495.          │ s,m: 00 01 02 03 00 03 01 05 00 00 00 00 00 00
  496.          │ d,m: 03 01
  497.          │ e,2m: 05 00
  498.          │
  499.  
  500.  
  501.  
  502.          !!!  And the effect $A+ and $A- can have.
  503.  
  504.          program x;
  505.          {$A-,B-,D+,E+,F-,G-,I+,L+,N-,O-,P-,Q-,R-,S+,T-,V+,X+}
  506.          var a,b,c:byte; d:word; e:byte;
  507.          var s:string;
  508.          begin
  509.            a:=1;b:=2;c:=3;d:=259;e:=5;
  510.            move(a,s[1],7);
  511.          end.
  512.         ┌────────────────────────────────── Watches ─────
  513.         │ a: 1
  514.         │ b: 2
  515.         │ c: 3
  516.         │ e: 5
  517.         │ a,7: 1,2,3,3,1,5,0
  518.         │ a,7m: 01 02 03 03 01 05 00
  519.         │ s,m: 00 01 02 03 03 01 05 00 00 00 00 00 00 00
  520.         │ d,m: 03 01
  521.         │ e,2m: 05 00
  522.         │
  523.  
  524.          $A+ a,7: 1,2,3,0,3,1,5
  525.          $A- a,7: 1,2,3,3,1,5,0
  526.  
  527.          ($A+ has "inserted a 0" before the word-var "d" (here the "3,1")
  528.           - for details see online help on $A (put cursor on $A, press CTRL+F1)
  529.             or manuals
  530.          )
  531.  
  532.  
  533.      ....BTW...END...................
  534.      )))
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.      Or, as I was suggested with a <g>, group them into records:
  542.  
  543.      program x;
  544.      const ar :record
  545.                  a,b,c,d,e:byte;
  546.                end = (a:1 ; b:2 ; c:3 ; d:4 ; e:5 );
  547.      begin
  548.      end.
  549. ╔═[■]══════════════════════════════ Watches ═════════════════════════════
  550. ║ ar: (1,2,3,4,5)
  551. ║ ar,r: (a:1;b:2;c:3;d:4;e:5)
  552.  
  553.      NOTE that the format-specifier ",r" adds the names of the
  554.      record-elements, which could be quite useful for larger records.
  555.  
  556.  
  557.      NOTE
  558.        Mixing CONST and VAR declaration won't be useful - the Borland's
  559.        Programmer manual indicates different "locations" for the "storage"
  560.        of CONST variables.
  561.  
  562.        That is to say for example:
  563.  
  564.         {$A- compiled}
  565.  
  566.         const byteVar:byte=$80;
  567.               userInput:string='';
  568.  
  569.         will have userInput[0] directly after byteVar -
  570.         Yet, this won't work for:
  571.  
  572.           const byteVar:byte=$80;
  573.           var   userInput:string;
  574.  
  575.         See Borland's programmer manual on details about "internals,
  576.         how variables are stored", CONST
  577.  
  578.         (again, I can't give titles or pages, since I don't have the
  579.          manuals in English
  580.         )
  581.  
  582.  
  583.  
  584.   BINARY FORMAT
  585.  
  586.      There seem to be no format-specifiers for eg. binary or octal format.
  587.      I'd suggest one of my procedures enclosed here for this conversion.
  588.  
  589.      It can surely be improved (eg. wouldn't work on x.xxxx, i.e. digits
  590.      after the "decimal"-point). Possible use while testing could be
  591.      adding test-code via $defined-compiling and then using a watch-variable
  592.      which displays the binary value.
  593.  
  594.  
  595.  -------------------------------------------------------------------------
  596.  
  597.  basisDesZahlenSystemsFuerDenString:
  598.   = the base of the system, eg 2 for binary, 8 for octal, 10 for decimal.
  599.  
  600.  dezimalzahl2string converts to "any system", just that you'd need to
  601.  expand "ch" for anything with a higher base as 16.
  602.  
  603.  
  604.  (((
  605.    BTW:
  606.      Actually the decimal-system is the odd one out. Converting from
  607.      binary to octal to hexadecimal is much easier. "laengeGruppierung"
  608.      gives the number of "chars" needed for conversion:
  609.  
  610.      8 binary chars = 3 octal chars = 2 hexa-decimal chars.
  611.  
  612.      eg: binary  11111111
  613.  
  614.         =      11 111 111
  615.        octal    3   7   7
  616.         =       1111 1111
  617.        hexa        F    F
  618.  
  619.      If you'd like some homework, convert your Compuserve-Address from
  620.      its octal format to hexa-decimal format.
  621.      Or convert the hexa-decimal value $000000000009 to decimal format.
  622.    -------------------------------------------------------------------------
  623.  )))
  624.  
  625. *)
  626.  
  627.  program x;
  628.  var pB:^Byte; w:word; s:string;
  629.  
  630.  {-DDDD---------------------------------------------------------------------}
  631.  FUNCTION dezimalzahl2string
  632.   ( zahl:longint;
  633.     basisDesZahlenSystemsFuerDenString:byte
  634.   ) :string;
  635.  CONST ch:array[0..15]of Char = '0123456789ABCDEF'; {max. für hexa-zahlen}
  636.  VAR s:string; laengeGruppierung:byte;
  637.  BEGIN
  638.    IF zahl < 0
  639.     THEN s:='-'
  640.    ELSE s[0]:=#0;
  641.    REPEAT
  642.      {Beim Restwertverfahren ergeben sich die Vorkommastellen "rückwärts"}
  643.      s:=ch[ (zahl mod basisDesZahlenSystemsFuerDenString) ] + s;
  644.      zahl:= zahl div basisDesZahlenSystemsFuerDenString;
  645.    UNTIL zahl = 0;
  646.    CASE basisDesZahlenSystemsFuerDenString OF
  647.      2:laengeGruppierung:=8;
  648.      8:laengeGruppierung:=3;
  649.      16:laengeGruppierung:=2;
  650.      ELSE laengeGruppierung:=0;
  651.    END;
  652.    IF laengeGruppierung<>0
  653.    THEN while (byte(s[0]) mod laengeGruppierung) <> 0 do s:='0'+s
  654.    ;
  655.    dezimalzahl2string:=s;
  656.  END; {dezimalzahl2string}
  657.  {--------------------------------------------------------------------------}
  658.  FUNCTION int2binStr (CONST zahl:longint):string;
  659.  VAR s:string; b:byte;
  660.  BEGIN
  661.    s:=dezimalZahl2String(zahl, 2);
  662.    b:=byte(s[0]);
  663.    while b>0 do begin
  664.      insert(' ',s,b-3);
  665.      insert('  ',s,b-7);
  666.      dec(b,8);
  667.    end;
  668.    int2BinStr:='BIN:'+s;
  669.  END; {Wandelt integer in eine Binärzahl im Format eines Strings}
  670.  {--------------------------------------------------------------------------}
  671.  begin
  672.    w:=259;
  673.  
  674.    s:='w->'+int2BinStr(w);
  675.    pB:=@w;
  676.    s:=s+' // pb->'+int2BinStr(pB^);
  677.  
  678.  { At this stage of the program, the watches would display:
  679.   ┌────────────────────────────────── Watches ───────────────────────
  680.   │ pB^,h: $3
  681.   │ pB^,2m: 03 01
  682.   │ w: 259
  683.   │ w,h: $103
  684.   │ w,m: 03 01
  685.   │ s[1],30mc: 'w->BIN:  0000 0001  0000 0011 '
  686.   │ s[30],60mc: ' // pb->BIN:  0000 0011
  687.   │
  688.  }
  689.  
  690.  
  691.    inc(pB);
  692.    s:=s+' // inc(pB)->'+int2BinStr(pB^);
  693.  
  694.  { At this stage of the program, the watches would display:
  695.   ┌────────────────────────────────── Watches ───────────────────────
  696.   │ pB^,h: $1
  697.   │ pB^,2m: 01 50
  698.   │ w: 259
  699.   │ w,h: $103
  700.   │ w,m: 03 01
  701.   │ s[1],30mc: 'w->BIN:  0000 0001  0000 0011 '
  702.   │ s[30],60mc: ' // pb->BIN:  0000 0011 // inc(pB)->BIN:  0000 0001
  703.   │
  704.  }
  705.  END.
  706.  
  707.  
  708.  
  709.  If you look at "w" as its value:
  710.      'w->BIN:  0000 0001  0000 0011 '
  711.  
  712.  inc(pB) seems to move "from the right to the left":
  713.  
  714.                 pb->BIN:  0000 0011
  715.  inc(pB)->BIN: 0000 0001
  716.  
  717.  This is not the case. As mentioned you need to look at "w",
  718.  as it is stored in memory, which is what "w,m" displays.
  719.  Hence pB did move from "the left to the right" as to be expected.
  720.  
  721.  
  722.  
  723.  
  724. (Copyright)Armin Schmitt at 100552.1041@compuserve.com
  725. Nov-1995,
  726. jC,v960224
  727.  
  728.  
  729.  Homework:
  730.  
  731.  octal                      100552.1041
  732.  =        1   0   0   5   5   2   .   1   0   4   1
  733.  =bin.  001 000 000 101 101 010   . 001 000 100 001
  734.  =           001000000101101010   . 001000100001
  735.  =       00 1000 0001 0110 1010   . 0010 0010 0001
  736.  =hexa.dec.    8    1    6    A   .    2    2    1
  737.  =
  738.  hexadecimal                  816A.221
  739.  
  740.  
  741.  hexadecimal $000000000009
  742.  =
  743.  decimal 9.0000000000000
  744.  
  745.